function list(state = [], action) {
    let NewState = JSON.parse(JSON.stringify(state))
    switch(action.type) {
        case "INIT":
            NewState = action.list
            return NewState
        case "ADD_ITEM":
            NewState.push(action.form)
            return NewState
        case "DEL_ITEM":
            NewState.splice(action.index, 1)
            return NewState
        case "SEARCH":
            NewState = NewState.filter(item => item.name.includes(action.value))
            return NewState
        case "EDIT":
            NewState = NewState.map(item => item.key === action.form.key? action.form: item)
            return NewState
        default:
            return state
    }
}

export {
    list
}